home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
PET
/
S-Super PET
/
(s)tz.d64
/
FORMATING.ASM
< prev
next >
Wrap
Assembly Source File
|
2009-01-18
|
4KB
|
114 lines
opt nolist ;FORMATING routine
xdef formating,format_integer
xref address,precision, buffer, buffer_2,digits_after_point
xref fixed_format,field_width,spaces,digits_before_point
xref suffixst_,fdiv_
xref length_,prefixst_,suffixst_,printf_,putnl_
xref fload_,ffloor_,ftest_,fneg_,fmulby_
xref faddhalf_,fdivby_,cnvf2s_,cnvs2f_,itos_
;routine rounds FP number (address in D) and adds string to BUFFER
formating std address
jsr fload_
jsr ftest_
stb sign
if lt ;if number is negative
jsr fneg_
endif
; - - - ROUNDING OF NUMBER - - -
ldd #precision ;number x (power of 10)
jsr fmulby_
jsr faddhalf_ ; + 0.5
jsr ffloor_ ;then is truncated
ldd #precision
jsr fdivby_ ;and devided by same number used to multiply
tst sign
if lt ;'-' restored, if needed
jsr fneg_
endif
ldd #buffer_2 ; conversion from FP to string
jsr cnvf2s_
ldy #buffer_2
clra
loop ;searching '.'
ldb a,y
cmpb #'.
quif eq
inca
endloop
sta position_point
leay a,y
lda digits_after_point
tst fixed_format
if eq ;if floating format
lda digits_after_point
loop ;trailing zeroes eliminated
ldb a,y
cmpb #'0
if ne
cmpb #'.
if eq
clra
else
inca
endif
bra four
endif
deca
until eq
else
inca ;if fixed format: truncate at next char
endif
four clr a,y ;string truncated
ldb position_point
subb digits_before_point
end_for_all if gt ;if number is too large
ldy #buffer_2
ldb field_width
lda #'- ;user can use any sign he (she) wishes
loop
sta ,y+
decb
until eq
clr ,y
else ;number is OK
sex
addd #spaces ;leading spaces added
ldy #buffer_2
pshs y
jsr prefixst_ ;address of BUFFER_2 left on stack
ldd #buffer_2 ;trailing spaces added
jsr length_
subb field_width ;maximum space allowed
sex ;negative sign is extended
addd #spaces ;address is so many bytes BEFORE
jsr suffixst_ ; SPACES
leas 2,s ;now P2 is removed
endif
ldd #buffer
pshs d
ldd #buffer_2
jsr suffixst_
leas 2,s
rts
format_integer pshs d
ldd #buffer_2
jsr itos_
leas 2,s
ldd #buffer_2
jsr length_
subb digits_before_point
bra end_for_all ;same end-of-routine as with FPs
position_point rmb 1
sign rmb 1
fcb 0